Skip to content

Add input validation (min binsize 30k) and skip cells with missing VCFs - #35

Open
tdalil wants to merge 2 commits into
VanLoo-lab:masterfrom
tdalil:add-input-validation
Open

Add input validation (min binsize 30k) and skip cells with missing VCFs#35
tdalil wants to merge 2 commits into
VanLoo-lab:masterfrom
tdalil:add-input-validation

Conversation

@tdalil

@tdalil tdalil commented Jun 22, 2026

Copy link
Copy Markdown

R/run_sc_sequencing.R:

  • Input validation: Added early file.exists() checks for tumour_bams and normal_bams to halt execution with a clear error if files are missing, saving unnecessary computation.
  • Genome build validation: Restricted the build argument to strictly "hg19", "hg38", or "mm39" using match.arg.

R/getAS_CNA.R:

  • Parallel Processing (mclapply): Added file presence checks (allele counts and VCFs) before processing each cell. Missing files now trigger a warning and skip the phasing step instead of crashing the entire run.
  • Robust VCF Parsing (readPhases):
    Optimized header removal using (z)grep -v '^##'.
    Added a tryCatch fallback using data.table::fread(skip="#CHROM") if the system command fails.
    Forced renaming of columns 4 and 5 to REF and ALT to prevent haplotype extraction errors.
    Returns empty data (integer(0)) for defective or empty VCFs to prevent cascading downstream crashes.

Copilot AI review requested due to automatic review settings June 22, 2026 11:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens input validation and improves robustness of allele-specific CNA processing by preventing hard failures when expected per-cell inputs (BAMs/VCFs/allele counts) are missing or malformed.

Changes:

  • Added early file existence validation for tumour/normal BAM inputs and restricted build via match.arg().
  • Enforced a minimum binsize of 30k and replaced several scalar logical operators with &&/||.
  • Made AS-CNA phasing/VCF parsing more defensive and added skipping behavior for missing per-cell inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
R/run_sc_sequencing.R Adds/adjusts early input validation, minimum binsize enforcement, and a few logical/robustness tweaks in the sequencing pipeline.
R/getAS_CNA.R Adds more robust VCF parsing and per-cell file checks to avoid crashing AS-CNA when inputs are missing/defective.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/run_sc_sequencing.R Outdated
Comment thread R/run_sc_sequencing.R
if(is.null(barcodes_10x))
{
if(!is.null(normal_bams[1]) & is.null(res$nlCTS.normal))
if(!is.null(normal_bams[1]) && is.null(res$nlCTS.normal))
Comment thread R/run_sc_sequencing.R
if(is.null(tumour_bams)) stop("tumour_bams cannot be NULL.")
if(!all(file.exists(tumour_bams))) stop("One or more files in tumour_bams do not exist.")
if(!is.null(normal_bams) && !all(file.exists(normal_bams))) stop("One or more files in normal_bams do not exist.")
build <- match.arg(build, choices = c("hg19", "hg38", "mm39"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build different from hg19, hg38 and mm39 should be accepted

Comment thread R/getAS_CNA.R
Comment on lines +76 to +77
cmd_str <- if(grepl("\\.gz$", x, ignore.case=TRUE)) paste0("zgrep -v '^##' ", x) else paste0("grep -v '^##' ", x)
df <- as.data.frame(data.table::fread(cmd=cmd_str))
Comment thread R/getAS_CNA.R
Comment on lines +90 to +93
if(ncol(x) >= 10 && !("REF" %in% colnames(x))) {
colnames(x)[4] <- "REF"
colnames(x)[5] <- "ALT"
}
Comment thread R/getAS_CNA.R
Comment on lines +451 to +457
ac_p <- if(length(list_ac_counts_paths)==1) list_ac_counts_paths[[1]] else list_ac_counts_paths[[x]]
ph_p <- if(length(path_to_phases)==1) path_to_phases[[1]] else path_to_phases[[x]]

if(!all(file.exists(ac_p)) || (!is.null(ph_p) && !all(file.exists(ph_p)))) {
warning(paste("Missing allele count or phasing files for cell", x, "- skipping AS CNA for this cell."))
return(NULL)
}
Comment thread R/getAS_CNA.R
Comment on lines +464 to +465
purity=if(any(grepl("refitted",names(res)))) res$allProfiles.refitted.auto[[x]]$purity else res$allSolutions[[x]]$purity,
ploidy=if(any(grepl("refitted",names(res)))) res$allProfiles.refitted.auto[[x]]$ploidy else res$allSolutions[[x]]$ploidy,
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants